package com.example.demo.controller;

import com.example.demo.model.Result;
import com.example.demo.searcher.DocSearcher;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2023-02-05
 * Time: 18:03
 */
@RestController
public class DocSearcherController {
    @Autowired
    private  DocSearcher docSearcher;

    @RequestMapping(value = "/searcher", produces = "application/json;charset=utf-8")
    @ResponseBody
    public List<Result> search(@RequestParam("query") String query) throws JsonProcessingException {

        //参数query是来自于url中的query string中的query中的key
        List<Result> results = docSearcher.search(query);
        return results;


    }
}
